package cn.fboost.mtos.controller;

import cn.fboost.mtos.annotation.RoleIs;
import cn.fboost.mtos.dto.Response;
import cn.fboost.mtos.dto.internal.Session;
import cn.fboost.mtos.service.UploadService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RoleIs({Session.Role.ADMIN})
@RestController
@RequestMapping("upload")
public class UploadController {
    private final UploadService uploadService;

    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }

    /**
     * 上传文件
     *
     * @param file 文件字段
     * @return {@link Response}
     */
    @PostMapping()
    public Response upload(@RequestParam("file") MultipartFile file) {
        return uploadService.upload(file);
    }
}
